<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>集合的实践</title>
</head>
<body>

</body>
<script type="text/javascript">
    //1. 数组去重
    // let arr = ['大事儿','小事儿','好事儿','坏事儿','小事儿'];
    // function quchong(arg){
    //     return [...new Set(arg)];
    // }
    // let quchong = arg => [...new Set(arg)];
    // console.log(quchong(arr));

    //2. 交集
    // let arr = [1,2,3,4,5,1];
    // let arr2 = [3,4,5,6,7,3];
    // let result = [...new Set(arr)].filter(item => {
    //     //创建 arr2 集合
    //     let s = new Set(arr2);
    //     //检测集合中是否存在 item 元素
    //     if(s.has(item)){
    //         return true;
    //     }else{
    //         return false;
    //     }
    // });
    // let result2 = [...new Set(arr)].filter(item => new Set(arr2).has(item));
    // console.log(result2);

    //3. 并集
    // let result3 = [...new Set([...arr, ...arr2])];
    // console.log(result3);

    //4. 差集
    // let result4 = [...new Set(arr)].filter(item => !new Set(arr2).has(item));
    // console.log(result4);
    

</script>
</html>